package com.api.syh56.shengyunhui.controller;

import com.api.syh56.shengyunhui.common.CommonResult;
import com.api.syh56.shengyunhui.entity.Goods;
import com.api.syh56.shengyunhui.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /**
     * 货源插入
     * @param goods
     * @return
     */
    @PostMapping("insert")
    public CommonResult<Goods> insert (@RequestBody Goods goods){
        goodsService.insert(goods);
        System.out.println(goods.getId());
        return CommonResult.success(goods);
    }

    /**
     * 货源删除
     * @param goods
     * @return
     */
    @PostMapping("del")
    public CommonResult<Object> delByid (@RequestBody Goods goods){
        goodsService.del(goods);
        return CommonResult.success(null);
    }


    /**
     * 货源更新
     * @param goods
     * @return
     */
    @PostMapping("update")
    public CommonResult<Object> updateById(@RequestBody Goods goods){
        goodsService.updateById(goods);
        return CommonResult.success(null);
    }

    /**
     * 货源列表
     * @return
     */
    @PostMapping("selectAll")
    public CommonResult<Object> selectAll(){
        List<Goods> goods = goodsService.selectAll();
        return CommonResult.success(goods);
    }

    /**
     * 货源id选择
     * @param goods
     * @return
     */
    @PostMapping("selectBy")
    public CommonResult<Object> selectBy(@RequestBody Goods goods){
        List<Goods> goodsList = goodsService.selectBy(goods);
        return CommonResult.success(goodsList);
    }
}
